package com.o2o.app.utils;

import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;

public class MagusTools {

	/**
	 * 得到一个popwindow
	 * 
	 * @param activity
	 *            所在activity
	 * @param layout
	 *            要生成popwindow的布局
	 * @param animid
	 *            pop的动画文件 使用系统默认的传-1
	 * @return 根据参数生成的popwindow
	 */
	public static PopupWindow getPopupWindow(Activity activity, int layout,
			int animid) {
		PopupWindow mPop = new PopupWindow(activity.getLayoutInflater()
				.inflate(layout, null), LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT, true);
		if (animid != -1) {
			mPop.setAnimationStyle(animid);
		}
		mPop.setBackgroundDrawable(new BitmapDrawable());
		return mPop;
	}

	/**
	 * 得到一个popwindow
	 * 
	 * @param activity
	 *            所在activity
	 * @param layout
	 *            要生成popwindow的布局
	 * @param animid
	 *            pop的动画文件 默认传-1.
	 * @param width
	 *            pop的宽度
	 * @param height
	 *            pop的高度
	 * @return 根据参数生成的popwindow
	 */
	public static PopupWindow getPopupWindow(Activity activity, int layout,
			int animid, int width, int height) {
		PopupWindow mPop = new PopupWindow(activity.getLayoutInflater()
				.inflate(layout, null), width, height, true);
		if (animid != -1) {
			mPop.setAnimationStyle(animid);
		}
		mPop.setBackgroundDrawable(new BitmapDrawable());
		return mPop;
	}
}
